﻿
//各向同性Mise弹塑性材料

#ifndef ElastoPlastic_H_
#define ElastoPlastic_H_
#include "StructuralMaterial.h"
#include "PiecewiseLinearFunction.h"
#include "SMatStatus.h"
#include "../../Analysis.h"
#define ElastoPlastic_Name "elastoplastic"

class ElastoPlastic : public StructuralMaterial
{
protected:
	double G; 
	double K; 
	double E; 
	double NU;
	DoubleArray epDataIso; 
	DoubleArray sigmaYDataIso; 
	DoubleArray epDataKin; 
	DoubleArray sigmaYDataKin; 
public:
	ElastoPlastic(int n, Domain* domain);
	virtual ~ElastoPlastic();

	MatStatus* CreateMatStatus(IntegrationPoint* p) const override;

	/**
	 * \brief 读入文件初始化
	 */
	void initial(Tag& tag) override;

	const char* GetClassName() const override
	{
		return "ElastoPlastic";
	}

	tens4ds Get3dMaterialStiffness_smallstrain(TimeStep* ctime, MaterialStiffnessMode rmode, IntegrationPoint* ip) override;

	void GetPlaneStrainMaterialStiffness_smallstrain(fmatrix<4, 4>& answer, TimeStep* ctime, MaterialStiffnessMode rmode, IntegrationPoint* ip) override;

	void ComputePlaneStrainRealStress(TimeStep* ctime, IntegrationPoint* ip) override;

	void Compute3dRealStress(TimeStep* ctime, IntegrationPoint* gp) override;


	void Compute3dCauchyStress(TimeStep* ctime,
	                           IntegrationPoint* ip) override;

	void ComputePlaneStrainCauchyStress(TimeStep* ctime, IntegrationPoint* ip) override;

	tens4ds Compute3dMatStiffMatrix_dSdE(TimeStep* ctime, MaterialStiffnessMode rmode, IntegrationPoint* ip) override;
	tens4ds Compute3dMatStiffMatrix_dSigde(TimeStep* ctime, MaterialStiffnessMode rmode, IntegrationPoint* ip) override;
	void ComputePlaneStrainStiffMatrix_dSdE(fmatrix<4, 4>& answer, TimeStep* ctime, MaterialStiffnessMode rmode, IntegrationPoint* ip) override;
	void ComputePlaneStrainMatStiffMatrix_dSigde(fmatrix<4, 4>& answer, TimeStep* ctime, MaterialStiffnessMode rmode, IntegrationPoint* ip) override;

	void Compute3dPK2Stress(TimeStep* ctime, IntegrationPoint* ip) override;
	void ComputePlaneStrainPK2Stress(TimeStep* ctime, IntegrationPoint* ip) override;

	bool CMisSymmetric(MaterialStiffnessMode rmode) override { return true; }


private:

	double isohardeningSigma(double ep);

	double isohardeningH(double ep);

	double kinhardeningSigma(double ep);

	double kinhardeningH(double ep);
};


class ElastoPlastic3dStatus : public SMatStatus3d
{
public:
	double equivalentPlasticStrain; 
	double tmpEquivalentPlasticStrain; 

	mat3ds plasticStrain; 
	mat3ds tmpPlasticStrain; 

	mat3ds backStress;
	mat3ds tmpBackStress;

	mat3ds stril; ///< 试应力

	ElastoPlastic3dStatus(int n, Domain* d, IntegrationPoint* p);

	virtual ~ElastoPlastic3dStatus()
	{
	}


	// 重载的函数
	const char* GetClassName() const override;
	void UpdateYourself(TimeStep*) override;
	void PrintOutputAt(FILE* fp, TimeStep* ctime) override;
};
#endif
